package cn.jsj.cxsys.dao;

import java.util.*;
import cn.jsj.cxsys.pojo.*;
import org.apache.ibatis.annotations.*;

public interface StudentDoLab
{
    @Insert({ "insert into tb_message (student_id,lab_id,apply_message,teacher_id,student_read,apply_time) values (#{studentID},#{labID},#{messageInf},(select lader_id from tb_lab where lab_id=#{labID}),1,#{applyTime})" })
    int pushApplyMessage(final LabMessage labMessage);

    @Select({ "select count(*) from tb_message where lab_id=#{labID} and student_id=#{studentID} and reply_time is null" })
    int checkPushedThisMessage(final LabMessage labMessage);

    @Select({ "select count(*) from tb_appled where lab_id=#{labID} and user_id=#{userID}" })
    int checkStudentHavePrivelageOfLab(@Param("labID") final int labID, @Param("userID") final int userID);

    @Results(id = "toLabMessage", value = { @Result(id = true, property = "messageID", column = "message_id"), @Result(property = "studentID", column = "student_id"), @Result(property = "teacherID", column = "teacher_id"), @Result(property = "messageInf", column = "apply_message"), @Result(property = "labID", column = "lab_id"), @Result(property = "result", column = "result"), @Result(property = "responseInf", column = "result_message"), @Result(property = "applyTime", column = "apply_time"), @Result(property = "replyTime", column = "reply_time"), @Result(property = "student.userID", column = "student_id"), @Result(property = "student.teleNumber", column = "tele_number"), @Result(property = "student.name", column = "name"), @Result(property = "student.className", column = "class_name"), @Result(property = "student.account", column = "account"), @Result(property = "lab.labID", column = "lab_id"), @Result(property = "lab.labName", column = "lab_name"), @Result(property = "lab.labNum", column = "lab_num") })
    @Select({ "select * from vi_message where student_read=0 and student_id=#{studentID}" })
    List<LabMessage> getApplyResult(@Param("studentID") final int studentID);

    @ResultMap({ "toLabMessage" })
    @Select({ "select * from vi_message where student_id=#{studentID}" })
    List<LabMessage> getAllMessageOfStudent(@Param("studentID") final int studentID);

    @Results(id = "toLab", value = { @Result(id = true, property = "labID", column = "lab_id"), @Result(property = "labName", column = "lab_name"), @Result(property = "labNum", column = "lab_num"), @Result(property = "description", column = "description"), @Result(property = "laderName", column = "name"), @Result(property = "laderTeleNumber", column = "tele_number"), @Result(property = "StudentNumber", column = "stu_count") })
    @Select({ "select * from vi_lab where lab_id in (select lab_id from tb_appled where user_id=#{userID})" })
    List<Lab> getAppledLabs(@Param("userID") final int userID);

    @Select({ "select lab_id from tb_appled where user_id=#{userID}" })
    List<Integer> getAppledLabIDs(@Param("userID") final int userID);

    @Update({ "update tb_message set student_read=1 where student_id=#{userID} and message_id=#{messageID}" })
    int deleteOneMessage(@Param("userID") final int userID, @Param("messageID") final int messageID);
}